// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Data/MissionStruct.h"
#include "Data/CommonEnum.h"
#include "SingleObjectiveWidget.generated.h"


UCLASS()
class MISCELLANEOUSPROJECT_API USingleObjectiveWidget : public UUserWidget
{
	GENERATED_BODY()

	virtual void NativeConstruct() override;
	virtual void NativeOnInitialized() override;
public:
	void ContructWidget(FObjectives ObjectiveInfo);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void ToggleSingleObjective(EToggleVisibility LVisibility);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void UpdateAsCompleted();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	float InProgress();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void LerpProgress();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	int32 CalculateAmount(TArray<FAssignedObjectiveTarget> InArray);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void IncreaseAssignedTarget(TSubclassOf<AActor> Class, int32 Amount);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void AddOrIncreaseTarget(FAssignedObjectiveTarget ObjectiveTarget);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void ContainsInTargets(FAssignedObjectiveTarget ObjectiveTarget, bool& Contains, int32 Amount);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void CountAddedAmount(int32 Add);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void UpdateProgressText();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	int32 FindInTargets(FAssignedObjectiveTarget ObjectiveTarget);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void AddProgress(FAssignedObjectiveTarget ObjectiveTarget);
private:
	void DelayLater();
public:
	UPROPERTY(meta = (BindWidget))
	class UTextBlock* AmountText;
	UPROPERTY(meta = (BindWidget))
	class UTextBlock* ObjectiveTitle;
	UPROPERTY(meta = (BindWidget))
	class UBorder* InnerFrame;
	UPROPERTY(meta = (BindWidget))
	class UProgressBar* Progress;
	UPROPERTY(meta = (BindWidget))
	class USizeBox* ProgressBarFrame;

	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ExposeOnSpawn = "true"), Category = "Default")
	FObjectives ObjectiveInfo;
	float MaxInProgress;

	TArray<FAssignedObjectiveTarget> Targets;
	float CurrentInProgress;
	float NewProgress;
	FTimerHandle LoopTimer;
	FTimerHandle LerpTimer;
	int32 ToAdd;
	int32 AddedAmount;
	bool Completed;
};
